package com.scs.application.core.exceptions;

import cn.hutool.core.util.StrUtil;

/**
 * @Description: 业务异常
 */
public class BusinessException extends RuntimeException {

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    /**
     * @Description： 抛出异常
     * @param message 我是{}异常
     * @param args 占位符填充字符串
     */
    public static void throwError(String message, String... args) throws BusinessException {
        throw new BusinessException(StrUtil.format(message,args));
    }

    /**
     * @Description： 抛出异常
     * @param message 我是{}异常
     * @param args 占位符填充字符串
     */
    public static void throwError(String message, Object... args) throws BusinessException {
        throw new BusinessException(StrUtil.format(message,args));
    }

    /**
     * @Description：抛出异常
     */
    /**
     * @Description： 抛出异常
     * @Author wyt
     * @Date 2023-05-05
     * @param isThrow true:抛出异常
     * @param message 我是{}异常
     * @param args 占位符填充字符串
     */
    public static void throwErrorIf(boolean isThrow , String message, String... args) throws BusinessException {
        if (!isThrow) {
            return;
        }
        throw new BusinessException(StrUtil.format(message,args));
    }

    /**
     * @Description：抛出异常
     */
    /**
     * @Description： 抛出异常
     * @Author wyt
     * @Date 2023-05-05
     * @param isThrow true:抛出异常
     * @param message 我是{}异常
     * @param args 占位符填充字符串
     */
    public static void throwErrorIf(boolean isThrow , String message, Object... args) throws BusinessException {
        if (!isThrow) {
            return;
        }
        throw new BusinessException(StrUtil.format(message,args));
    }

}
